<?php

class MMenu {

    const EOL = "\n";
    const TAB = "\t";
    
    public function renderAllMenus($module) {
        // Getting all menus of the specified module
        $menuArray = Module::find('first', array('conditions'=>array('name=?', $module)));
        if (!empty($menuArray)){
            $menus = $menuArray->ml_menus;
            $return = self::TAB.'<ul>'.self::EOL;
            foreach($menus as $menu)
            {
                $return .= self::TAB.'<li><a href="';

                switch($menu->type) {
                    case "module":
                        $return .= '?r=';
                        break;
                    case "page":
                        $return .= '?r='.$module.'&'.Mandrill::getApp()->routeKeys['page'].'=';
                        break;
                    case "link":
                        $return .= '?'.Mandrill::getApp()->routeKeys['redirect'].'=';
                }

                $return .= $menu->link.'">'.$menu->title.'</a></li>'.self::EOL;
            }
            $return .= self::TAB.'</ul>'.self::EOL;
        } else {
            $return = NULL;
        }
        return $return;
    }

    public static function renderAdminMenu($module){
        $menuFile = BASE_PATH.DS.Mandrill::getApp()->modulesFolder.DS.$module.DS.'admin'.DS.'views'.DS.'menu.php';
        ob_start();
        require($menuFile);
        $menuContent = ob_get_contents();
        ob_end_clean();
        return $menuContent;
    }

}

?>
